package com.epoint.mobileoa.tools;

import com.epoint.mobileoa.R;
import com.epoint.mobileoa.service.MainService;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;


/**
 * @author liyc
 * @time 2012-1-7 上午12:45:55
 * @annotation 
 */
public class ToastHelp {
	
	public static void showAndroidToastWorning(Context con,String msg)
	{
		Toast.makeText(con,Html.fromHtml("<font color=red>"+msg+"</font>"), Toast.LENGTH_LONG).show();
	}
	
	public static void showToast(Context con,String text){
		LayoutInflater vi = (LayoutInflater)con.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View view = vi.inflate(R.layout.incoming_message_panel,null);
		TextView tv = (TextView)view.findViewById(R.id.message);
		ImageView iv = (ImageView) view.findViewById(R.id.im_iv);
		iv.setBackgroundDrawable(con.getResources().getDrawable(R.drawable.epoint2));
		tv.setText(text);
		tv.setTextColor(Color.YELLOW);	
		Toast toast = new Toast(con);
		toast.setView(view);
		toast.setDuration(1000);
		toast.show();
	}
	
	public static void showToastCommon(Context con,String text){
		LayoutInflater vi = (LayoutInflater)con.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View view = vi.inflate(R.layout.toastcommon,null);
		TextView tv = (TextView)view.findViewById(R.id.message);
		ImageView iv = (ImageView) view.findViewById(R.id.im_iv);
		iv.setBackgroundDrawable(con.getResources().getDrawable(R.drawable.epoint2));
		tv.setText(text);
		tv.setTextColor(Color.YELLOW);
		Toast toast = new Toast(con);
		toast.setView(view);
		toast.setDuration(1000);
		toast.show();
	}
	
	public static void showToastCommonLong(Context con,String text){
		LayoutInflater vi = (LayoutInflater)con.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View view = vi.inflate(R.layout.toastcommon,null);
		TextView tv = (TextView)view.findViewById(R.id.message);
		ImageView iv = (ImageView) view.findViewById(R.id.im_iv);
		iv.setBackgroundDrawable(con.getResources().getDrawable(R.drawable.epoint2));
		tv.setText(text);
		tv.setTextColor(Color.YELLOW);
		Toast toast = new Toast(con);
		toast.setView(view);
		toast.setDuration(Toast.LENGTH_LONG);
		toast.show();
	}
	
	public static void showToastCommonLongHtml(Context con,String text){
		LayoutInflater vi = (LayoutInflater)con.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View view = vi.inflate(R.layout.toastcommon,null);
		TextView tv = (TextView)view.findViewById(R.id.message);
		ImageView iv = (ImageView) view.findViewById(R.id.im_iv);
		iv.setBackgroundDrawable(con.getResources().getDrawable(R.drawable.epoint2));
		tv.setText(Html.fromHtml(text));
		tv.setTextColor(Color.YELLOW);
		Toast toast = new Toast(con);
		toast.setView(view);
		toast.setDuration(Toast.LENGTH_LONG);
		toast.show();
	}
	
	public static void showToast(Context con,String text,int duration){
		LayoutInflater vi = (LayoutInflater)con.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View view = vi.inflate(R.layout.incoming_message_panel,null);
		TextView tv = (TextView)view.findViewById(R.id.message);
		ImageView iv = (ImageView) view.findViewById(R.id.im_iv);
		iv.setBackgroundDrawable(con.getResources().getDrawable(R.drawable.epoint2));
		tv.setText(text);
		Toast toast = new Toast(con);
		toast.setView(view);
		toast.setDuration(duration);
		toast.show();
	}
	
	public static void showToast(Context con,String text,int duration,int ico,int textcolor){
		LayoutInflater vi = (LayoutInflater)con.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View view = vi.inflate(R.layout.incoming_message_panel,null);
		TextView tv = (TextView)view.findViewById(R.id.message);
		ImageView iv = (ImageView) view.findViewById(R.id.im_iv);
		iv.setBackgroundDrawable(con.getResources().getDrawable(ico));
		if(textcolor!=0){
			tv.setTextColor(textcolor);	
		}
		tv.setText(text);
		Toast toast = new Toast(con);
		toast.setView(view);
		toast.setDuration(duration);
		toast.show();
	}
	
	/**
	 * 发送广播，显示Toast
	 */
	public static void sendBroadcastToast(Context con,String msg,int icon){
		Intent intent = new Intent(MainService.TaskAction);
		intent.putExtra("msg", msg);
		intent.putExtra("icon", icon==0?R.drawable.epoint2:icon);
		con.sendBroadcast(intent);
	}
}
